//
//  DrugprojectViewController.m
//  HarmonizePub
//
//  Created by apple on 2016/12/2.
//  Copyright © 2016年 All rights reserved.
//

#import "DrugdetailViewController.h"
#import "DrugrojectTableViewCell.h"
#import "HTTPSTool.h"
#import "URLTool.h"
#import "Config.h"
@interface DrugdetailViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView * mytabbleview;
    NSMutableArray * allarray;
    
}
@end

@implementation DrugdetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    allarray = [[NSMutableArray alloc] init];
    mytabbleview = [[UITableView alloc] initWithFrame:CGRectMake(10,10, [UIScreen mainScreen].bounds.size.width-20, [UIScreen mainScreen].bounds.size.height - 64 - 10) style:UITableViewStylePlain];
    mytabbleview.backgroundColor = [UIColor whiteColor];
    mytabbleview.delegate = self;
    mytabbleview.dataSource = self;
    mytabbleview.showsVerticalScrollIndicator = NO;
    mytabbleview.tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
    mytabbleview.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:mytabbleview];
    
    [self getinformationwith:_datadic];
    // Do any additional setup after loading the view from its nib.
}
-(void)getinformationwith:(NSDictionary *)dic
{
    NSDictionary *cookie = @{CookieVaule : [UserDefaultsTool stringForKey:XHToken]};
    NSDictionary * param = @{
                             @"name":dic[@"ypmc"]
                             };
    [HTTPSTool POSTRequestWithPath:XHgetDrugDetail cookie:cookie params:param success:^(NSDictionary * _Nonnull JSON) {
        XHLog(@"%@",JSON);
        [allarray removeAllObjects];
        allarray = [[NSMutableArray alloc] initWithArray:JSON[@"data"][@"list"]];
        [mytabbleview reloadData];
    }];
}
#pragma tableview 代理
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return allarray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    return allarray.count;
    if (allarray == nil || allarray.count == 0) {
        return 0;
    }else{
    return 1;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * inderstr = @"cell";
    DrugrojectTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:inderstr];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"DrugrojectTableViewCell" owner:nil options:nil] firstObject];
    }
       [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.titlenamelabel.text = [allarray objectAtIndex:indexPath.section][@"ypmc"];
    cell.DWlabel.text = [allarray objectAtIndex:indexPath.section][@"ypdw"];
    cell.CDlabel.text = [allarray objectAtIndex:indexPath.section][@"cdmc"];
//    cell.GGlabel.text = [allarray objectAtIndex:indexPath.section][@"ypdj"];
    cell.XSlabel.text =  [NSString stringWithFormat:@"%@",[allarray objectAtIndex:indexPath.section][@"ypdj"]];
//    cell.JLlabel.text = [NSString stringWithFormat:@"%@",[allarray objectAtIndex:indexPath.section][@"zfpb"]];

    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 152.0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section {
    view.tintColor = [UIColor clearColor];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
